#include "ResourceBank.h"
#include "../../Header/Header.h"

//template<class T>
ResourceBank::ResourceBank()
{
	m_Database.resize(0);
}

ResourceBank::~ResourceBank()
{
	int count = m_Database.size();
	for (int i = 0; i < count; i++)
	{
		Resource* temp = m_Database[i];
		SAFE_DEL(temp);
	}
	m_Database.clear();
}

int ResourceBank::Add(Resource* element)
{
	if (!element)
		return -1;
	m_Database.push_back(element);
	return 0;
}

int ResourceBank::Insert(Resource* element, int index)
{
	if (index >= m_Database.size())
		return -2;
	if (!m_Database[index])
		return -1;
	return 0;
}

int ResourceBank::Remove(int index)
{
	if (index >= m_Database.size())
		return -2;
	if (!m_Database[index])
		return -1;
	m_Database.erase(m_Database.begin()+index);
}

Resource* ResourceBank::Reference(int index)
{
	if (index >= m_Database.size() || !m_Database[index])
		return 0;
	return m_Database[index]->Reference();
}

void ResourceBank::Dereference(int index)
{
	if (index > m_Database.size() || !m_Database[index])
		return ;
	m_Database[index]->Dereference();
}